package departure;

import dbhandler.*;


import java.util.*;



/**
 *
 * @author Casper, Dennis, Jackie, Jakob
 * @version 1.00
 */
public class Bill {

    private Booking booking;
    private String payMethod;
    private ArrayList<Invoice> additional;
    private String billNo;
    private int endPrice;
    private int dayCount;

    /**
     *
     */
    public Bill() {
    }

    /**
     *
     * @param booking Booking
     * @param payMethod String representing the payMethod
     */
    public Bill(Booking booking, String payMethod) {
        this.booking = booking;
        additional = new ArrayList<Invoice>();
        dayCount = new Booking().getIntermediateDays(booking.getInDate(), booking.getOutDate()).size();
        this.payMethod = payMethod;
        billNo = booking.getGuest().getGuestNo() + "-" + booking.getRoom().getRoomNo() + "-" + booking.getBookingNo();
        fillArray();
    }

    public String getRoomNo() {
        String roomno = booking.getRoom().getRoomNo();
        return roomno;

    }

    public String getPeriod() {
        String period = booking.getInDate() + " - " + booking.getOutDate();
        return period;
    }

    public String getAdditionalLine(int index) {
        String text = additional.get(index).getText();
        return text;
    }

    public String getAdditionalPrice(int index) {
        int price = additional.get(index).getPrice();
        String priceSt = price + "";
        return priceSt;
    }

    public String getPayMethod() {
        return payMethod;
    }

    /**
     * Calculates the final payment according to the list of additionals
     * @return int endPrice representing the end price
     */
    public int calcEndPayment() {
        endPrice = 0;
        for (int i = 0; i < additional.size(); i++) {
            endPrice += additional.get(i).getPrice();
        }
        endPrice = endPrice * dayCount;
        return endPrice;
    }

    public int getDayCount() {
        return dayCount;
    }

    /**
     * Fills the ArrayList with productlines 
     */
    private void fillArray() {
        int catNo = booking.getRoom().getCategory().getCategoryNo();
        switch (catNo) {
            case 1:
                additional.add(new Invoice("Single Guest Room", 30));
                break;
            case 2:
                additional.add(new Invoice("Double Guest Room", 45));
                break;
            case 3:
                additional.add(new Invoice("Suite", 58));
                break;
            default:
                additional.add(new Invoice("No line", 0));
                break;
        }
        if (booking.getRoom().isExecutive()) {
            additional.add(new Invoice("   + Executive room", 15));
        } else {
            additional.add(new Invoice("", 0));
        }
        if (booking.getRoom().isOceanView()) {
            additional.add(new Invoice("   + oceanview", 10));
        } else {
            additional.add(new Invoice("", 0));
        }
    }

    /**
     * Draws the name of the guest to the bill.
     */
    public String drawGuestinfo() {
        String guestName = booking.getGuest().toString();
        return guestName;
    }


    @Override
    public String toString() {
        return "Bill String : BillNo" + billNo + " * GuestName " + booking.getGuest().toString()+" * Paymethod " + payMethod + " * Endprice" + endPrice;
    }

    public String getBillNo() {
        return billNo;
    }
}
